/*
 * @lc app=leetcode.cn id=14 lang=java
 *
 * [14] 最长公共前缀
 */

// @lc code=start
class Solution {
    public String longestCommonPrefix(String[] strs) {
        if(strs.length == 0) return "";
        
        String prefix = strs[0];
        int len = strs.length;

        for(int i = 1; i < len; i++) {
            int j = 0;
            for(; j < prefix.length() && j < strs[i].length(); j++) {
                if(prefix.charAt(j) != strs[i].charAt(j)) {
                    break;
                }

            }

            prefix = prefix.substring(0, j);
            if(prefix.equals("")) {
                return prefix;
            }
            
        }
        return prefix;
    }
}
// @lc code=end

